/**
 * @author: knowno
 * @create: 2025-09-10 13:51
 * @Version 1.0
 **/
public class Homework1 {
    /**
     * 使用数组和循环完成数组转置，如原始矩阵为{{1,2,3},{4,5,6}},转置后为{{1,4},{2,5},{3,6}}
     * @param args
     */
    public static void main(String[] args) {
        //2行3列
        int [][] array = {
                {1,2,3},
                {4,5,6}
        };
        int [][] temp = transpose(array);
        for (int i=0;i<temp.length;i++){
            for (int j=0;j<temp[0].length;j++){
                System.out.print(temp[i][j]+" ");
            }
            System.out.println();
        }

    }


    /**
     * 数组转置
     * @param array
     * @return
     */
    public  static  int[][] transpose(int [][] array){

        //行和列
        int row = array[0].length;
        int col = array.length;
        System.out.println(row+" "+col);
        int [][]temp = new int[row][col];
        //外循环控制行
        for (int i=0;i<row;i++){
            //内循环控制列
            for (int j=0;j<col;j++){
                //转置
                temp[i][j]=array[j][i];
            }
        }
        return temp;
    }
}
